a = input()
maxi = 0
if len(a) != 4:
    pass
else:
    b = list(a)
    
    for c in range(0, 3):
        for i in range(2, int(b[c] + b[c+1])):
            if int(b[c] + b[c+1]) % i == 0:
                break
        else:
            if int(b[c] + b[c+1]) > maxi:
                maxi = int(b[c] + b[c+1])
    
    for k in b:
        for i in range(2, int(k)):
            if int(k) % i == 0:
                break
        else:
            if int(k) > maxi:
                maxi = int(k)
    
    for i in range(2, int(a)):
        if int(a) % i == 0:
            break
    else:
        if maxi < int(a):
            maxi = int(a)
    
    for z in range(1, 3):
        for i in range(2, int(b[z-1] + b[z] + b[z+1])):
            if int(b[z-1] + b[z] + b[z+1]) % i == 0:
                break
        else:
            if int(b[z-1] + b[z] + b[z+1]) > maxi:
                maxi = int(b[z-1] + b[z] + b[z+1])

print(maxi)